<?php
/**
 * Created by XM·Tan.
 * Motto: Who shuts love out, in turn shall be shut out from love.
 * Date: 2021/1/20 3:41
 */

namespace app\common\lib;


class Show {

    /**
     * 返回 普通 json 数据格式
     * @param $status
     * @param string $message
     * @param array $data
     * @param int $httpStatus
     * @return \think\response\Json
     */
    public static function show($status, $message = "error", $data = [], $httpStatus = 200) {
        $result = [
            "status" => $status,
            "message" => $message,
            "result" => $data
        ];
        return json($result, $httpStatus);
    }

    /**
     * 成功 返回方法
     * @param array $data
     * @param string $message
     * @return \think\response\Json
     */
    public static function success($data = [], $message = "OK") {
        $result = [
            "status" => config('status.success'),
            "message" => $message,
            "result" => $data
        ];
        return json($result);
    }

    /**
     * 失败 返回方法
     * @param array $data
     * @param string $message
     * @param int $status
     * @param int $httpStatus
     * @return \think\response\Json
     */
    public static function error($message = "error", $data = [], $status = 0, $httpStatus = 200) {
        $result = [
            "status" => $status,
            "message" => $message,
            "result" => $data
        ];
        return json($result, $httpStatus);
    }


    /**
     * 返回 layui 数据表格所需 json 数据格式
     * @param $code
     * @param $msg
     * @param $count
     * @param $data
     * @param int $httpStatus
     * @return \think\response\Json
     */
    public static function show_lay_table($code, $msg, $count, $data, $httpStatus = 200) {
        $result = [
            "code"  => $code,
            "msg"   => $msg,
            "count" => $count,
            "data"  => $data
        ];
        return json($result, $httpStatus);
    }

}